import redis

def main():
    client = redis.Redis(host='192.168.221.137',port=6379,
                         password='1qaz2wsx')
    print(client)
    client.set('username','tom',ex=300)
    print(client.ttl('username'))
    # get会获取到字节段，想要获取字符段需要对其编码
    print(client.get('username').decode())

    client.set('yuting','300')
    # 加1
    client.incr('yuting')
    # 加50票
    client.incrby('yuting',50)
    print(client.get('yuting').decode())

    client.hset('stu1','id','1001')
    client.hset('stu1','name','张三')
    print(client.hgetall('stu1'))
if __name__ == '__main__':
    main()